package awk.javarmiiiop;

import awk.javarmiiiop.HelloImpl;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;

public class HelloServer {
    public final static String JNDI_FACTORY = "com.sun.jndi.cosnaming.CNCtxFactory";

    public static void main(String[] args) {
        try {
            System.setProperty("java.rmi.server.codebase", "http://127.0.0.1:8000/");
            //使用JNDI在命名服务中发布引用
            Hashtable<String,Object> env = new Hashtable<>();
            env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
            env.put(Context.PROVIDER_URL, "iiop://127.0.0.1:1050");
            InitialContext initialContext = new InitialContext(env);
            initialContext.rebind("HelloService", new HelloImpl());

            System.out.println("Hello Server Ready...");
            Thread.currentThread().join();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
